package com.hm.scala

import scala.collection.mutable.HashMap

object MyMap {

  def main(args: Array[String]): Unit = {

    //定义固定map

    var ma = Map("a" -> "123", "b" -> "456", "c" -> "789");
    println(ma("b"))

    ma = Map(("a", "123"), ("b", "456"), ("c", "789"))
    println(ma("c"))

    println("----------华丽的分割线------------")

    val map = new HashMap[String, String]();
    map.put("aa", "11");
    map.put("ab", "12");
    map.put("ac", "13");

    println(map("aa"))
    println(map.get("aa"))
    println(map.getOrElse("aa", "aa数据没找到"))
    println(map.getOrElse("cc", "cc数据没找到"))

    //key set遍历
    for (a <- map.keySet if a != "ab") {
      println("keyset-->" + a + "=>" + map(a))
    }

    //value遍历
    for (v <- map.values) {
      println("value==》" + v)
    }

    //option
    val a: Option[Int] = Some(5);
    val b: Option[Int] = None

    println(a.isEmpty + ";" + b.isEmpty)

  }
}